-
Notifications
You must be signed in to change notification settings - Fork 23
Align strides with numpy #2747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Align strides with numpy #2747
Conversation
|
View rendered docs @ https://intelpython.github.io/dpnp/pull/2747/index.html |
|
Array API standard conformance tests for dpnp=0.20.0dev2=py313h509198e_28 ran successfully. |
3b983e6 to
53bebfd
Compare
53bebfd to
d6ead2f
Compare
dpnp/dpnp_iface_indexing.py
Outdated
| out_offset = st_m // a.itemsize * offset | ||
| else: | ||
| out_shape = a_shape[:-2] + (0,) | ||
| out_strides = a_straides[:-2] + (1,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the logic here also needs to be updated because currently dpnp returns incorrect strides compared to NumPy. Could you also add a test to cover this case?
a = dpnp.arange(10).reshape(2,5)
a_np = numpy.arange(10).reshape(2,5)
dpnp.diagonal(a, offset=5).strides
# (0. )
numpy.diagonal(a_np, offset=5).strides
# (48, )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that wasn't aligned on the master as well:
a = np.arange(10).reshape(2,5)
np.diagonal(a, offset=5).strides
# Out: (1,)Btw I will update the code to keep the same behavior as was on the master. But I wonder if there is a strict requirement on strides equality with NumPy for a 0-size array. In any case it'd be better to handle that (if needed) in the seprarte PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antonwolfy Thanks for bringing this distinction. Just curious to know if dpnp/dpctl recommends any particular numpy version dependency for testing. The app I was working with failed too with the diagonal method in stacktrace.
Would the below legacy behavior be restored, only when the offsets is outside the bounds and rest of the functionality to changed to number of bytes from number of items ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious to know if dpnp/dpctl recommends any particular numpy version dependency for testing.
We are targeting to align with the latest published numpy version.
The app I was working with failed too with the diagonal method in stacktrace.
Could you please share an example of the code with failure? It might be some other issue we have to resolve.
Would the below legacy behavior be restored, only when the offsets is outside the bounds and rest of the functionality to changed to number of bytes from number of items ?
Everywhere it will be to return the number of bytes.
In case when the offsets is outside the bounds, previously dpnp returns strides end with ...,1), and now it will end with ..., 1 * a.itemsize).
The "legacy" in that use case means "different from the numpy" for returned 0-sized array.
The PR changes implementation of
stridesproperty indpnp.ndarrayto align with NumPy and CuPy and to return bytes displacement in memory (previously and in dpctl it returns elements displacement).